package com.tzz.controller;

import com.tzz.entity.HttpResult;
import com.tzz.entity.Station;
import com.tzz.exception.AddExistException;
import com.tzz.service.StationService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/pre/station")
public class StationController {
    @Autowired
    StationService stationService;

    @PostMapping("/query")
    public HttpResult<List<Station>> getStation(@RequestBody Station station){
        Logger log = LoggerFactory.getLogger(StationController.class);
        log.info("控制台消息");
        log.debug("debug消息");
        log.error("error消息");
        return HttpResult.success(stationService.findStationsByNameId(station));
    }

    @PostMapping("/add")
    public HttpResult<Station> addStation(@RequestBody @Validated Station station) throws AddExistException {
//        System.out.println(station);
        stationService.addStation(station);
        return HttpResult.success(station);
    }

    @PostMapping("/delete")
    public HttpResult<Object> deleteStation(@RequestBody HashMap<String,Integer> id){
        stationService.changeStationStaus(id.get("id"));
        return HttpResult.success();
    }
}
